import { GrowlMessageType } from './../../components/messageBox/growMeaageType';
import { currentFramework, adapter } from './adapter';
import { InitializationService } from './index';
import { PrividerService } from "./prividerService"
const Component = require('@angular/core').Component;

@Component(adapter.warpComponentMeta({
    styleUrls: ['./index.scss'],
    template: `
        <div class="remotelogin-container">
            <header>
                <i class="material-icons back divvma" (click)="onBack()">arrow_back</i>
                <h1 class="padding">管理登录</h1>
                <div class="nav">
                    <i ></i>
                    <i ></i>
                    <i class="active">3</i>
                    <i ></i>
                </div>
            </header>
            <div class="padding tip ">
                <p class="p1 title">请使用店长或店铺管理员账号登录</p>
            </div>
            <div class="padding form ">
                <md-input-container>
                    <input md-input placeholder="请输入账号" [(ngModel)]="user.username" maxLength="100" />
                </md-input-container>
                <md-input-container>
                    <input md-input placeholder="请输入密码" [(ngModel)]="user.password" type="password" maxLength="100" />
                </md-input-container>
                <button  (click)="login()">登录</button>
            </div>
        </div>
    `
}))
export default class RemoteLogin {
    user = { username: "", password: "" };
    onBack() {
        PrividerService.current.navigate(InitializationService.current.getPathByComponentName("checkEnv"))
    }
    async login() {
        try {
            let {user, token} = await PrividerService.current.doCloudLogin(this.user.username, this.user.password);
            const store = PrividerService.current.doLocalstorageGetItem("preStore");
            const LDCConfig = PrividerService.current.doLocalstorageGetItem("preLDCConfig") && PrividerService.current.doLocalstorageGetItem("preLDCConfig").value;
            const adsAbout = PrividerService.current.doLocalstorageGetItem("adsAbout");
            // localStorage.clear();
            InitializationService.current.onComplete({ store, LDCConfig, user, adsAbout, token })
        } catch (error) {
            console.log(error);
            PrividerService.current.errorGrow(error.msg || error);
        }
    }
}
